<?php

namespace App\Admin\Controllers;

use App\UserOrderDist;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Table;

class DistController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'UserOrderDist';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserOrderDist());
        $grid->model()->orderBy('id', 'desc');

        $grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();
        
            // 在这里添加字段过滤器
            $filter->equal('oid', '订单id');
        
        });

        $grid->column('id', __('Id'));
        $grid->column('oid', __('Oid'))->expand(function ($model) {
            return new Table(['内容'], json_decode($model->text, true));
        });
        $grid->column('created_at', __('Created at'));

        // 全部关闭
        $grid->disableActions();

        return $grid;
    }

}
